/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO.InformationFilter;

import DAO.DAOAccess;
import java.security.Timestamp;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;

/**
 *
 * @author tran tuan tai
 */
public class PrdTotalPageDAO
{
   private static PrdTotalPageDAO m_instance = new PrdTotalPageDAO();
    private PrdTotalPageDAO()
    {}

    public static PrdTotalPageDAO GetInstance()
    {
        return m_instance;
    }



    public int Insert(int period, int totalpage)
    {
        int id = -1;
        java.sql.Connection conn = DAOAccess.GetConnection();
        String sql = "INSERT INTO PERIODTOTALPAGE(PERIOD, TOTALPAGE) VALUES(?, ?)";
        try
        {
            PreparedStatement stat = conn.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
            stat.setInt(1, period);
            stat.setInt(2, totalpage);

            stat.executeUpdate();
            ResultSet result = stat.getGeneratedKeys();
            result.first();
            id = result.getInt(1);

            stat.close();
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return id;
    }

    public void DoEmpty()
    {
        try
        {
            java.sql.Connection conn = DAOAccess.GetConnection();
            String sql = "DELETE FROM PERIODTOTALPAGE";
            PreparedStatement stat = conn.prepareCall(sql);
            stat.execute();
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }
}
